package com.zk.shop.service.Impl;

import com.zk.shop.dao.AdminDao;
import com.zk.shop.entity.Admin;
import com.zk.shop.service.AdminService;
import com.zk.shop.util.SqlSessionFactoryUtil;
import org.apache.ibatis.session.SqlSession;

import java.util.List;

public class AdminServiceImpl implements AdminService {
    SqlSession session= SqlSessionFactoryUtil.getSqlSession();
    AdminDao adminDao=session.getMapper(AdminDao.class);

    @Override
    public List<Admin> showAdmin() {
        return adminDao.showAdmin();
    }

    @Override
    public boolean addAdmin(Admin admin) {
        boolean flag=adminDao.addAdmin(admin);
        try {
            if (flag){
                session.commit();
            }
        }catch (Exception e){
            e.printStackTrace();
        }finally {
            session.close();
        }

        return flag;
    }

    @Override
    public Admin selFlagById(int id) {
        return adminDao.selFlagById(id);
    }

    @Override
    public boolean updateAdminPwd(Admin admin) {
        boolean flag=adminDao.updateAdminPwd(admin);
        try {
            if (flag){
                session.commit();
            }
        }catch (Exception e){
            e.printStackTrace();
        }finally {
            session.close();
        }
        return flag;
    }

    @Override
    public boolean updateAdminFlag(Admin admin) {
        boolean flag=adminDao.updateAdminFlag(admin);
        try {
            if (flag){
                session.commit();
            }
        }catch (Exception e){
            e.printStackTrace();
        }finally {
            session.close();
        }
        return flag;
    }

    @Override
    public boolean delAdmin(int id) {
        boolean flag=adminDao.delAdmin(id);
        try {
            if (flag){
                session.commit();
            }
        }catch (Exception e){
            e.printStackTrace();
        }finally {
            session.close();
        }
        return flag;
    }

    @Override
    public Admin loginCheck(Admin admin) {
        return adminDao.loginCheck(admin);
    }
}
